﻿
using Xacml.Core;
using Xacml.Core.Interfaces;
using System;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class FunctionElementReadWrite : XacmlElement, IExpression
  {
    private string _functionId;

    public virtual string FunctionId
    {
      get
      {
        return this._functionId;
      }
      set
      {
        this._functionId = value;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    public FunctionElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      if (reader.LocalName == "Function" && this.ValidateSchema(reader, schemaVersion))
        this._functionId = reader.GetAttribute("FunctionId");
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    public FunctionElementReadWrite(string functionId, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      this._functionId = functionId;
    }

    public void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("Function");
      if (this._functionId != null)
        writer.WriteAttributeString("FunctionId", this._functionId);
      writer.WriteEndElement();
    }
  }
}
